package com.yang.news.web.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.yang.news.model.dto.ChinaHolidayDTO;
import com.yang.news.model.dto.SentenceDTO;
import com.yang.news.model.dto.VisitorCountDTO;
import com.yang.news.model.result.ResultModel;
import com.yang.news.service.ChinaHolidayService;
import com.yang.news.service.SentenceService;
import com.yang.news.service.VisitLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 首页访问统计
 * @author Billyang
 * @date 2024/11/29 14:30
 */
@RestController
@RequestMapping("/api/welcome")
public class WelcomeController {
    @Autowired
    private VisitLogService visitLogService;

    @Autowired
    private SentenceService sentenceService;

    @Autowired
    private ChinaHolidayService chinaHolidayService;

    @GetMapping("/queryVisitorCount")
    public ResultModel<VisitorCountDTO> queryVisitorCount() {
        Date now = new Date();
        DateTime startTime = DateUtil.beginOfDay(now);
        DateTime endTime = DateUtil.endOfDay(now);
        return ResultModel.success(visitLogService.queryVisitorCount(startTime, endTime));
    }

    @GetMapping("/querySentence")
    public ResultModel<SentenceDTO> querySentence() {
        return ResultModel.success(sentenceService.querySentence());
    }

    @GetMapping("/queryHoliday")
    public ResultModel<List<ChinaHolidayDTO>> queryHoliday(@RequestParam String month) {
        return ResultModel.success(chinaHolidayService.queryHoliday(month));
    }
}
